import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vite.dev/config/
import { fileURLToPath, URL } from 'url'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '@cimom/ci-web-plugins-commom-css': '@cimom/ci-web-plugins-commom/dist/CI.Web.Plugins.Commom.css'
    }
  },
  build: {
    lib: {
      entry: 'src/index.js',
      name: 'CI.Web.Plugins.Commom',
      fileName: (format) => `CI.Web.Plugins.Commom.${format}.js`,
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ['vue'],
      output: {
        globals: {
          vue: 'Vue',
        },
        exports: 'named',
        assetFileNames: (assetInfo) => {
          if (assetInfo.name && assetInfo.name.endsWith('.css')) {
            return 'CI.Web.Plugins.Commom.css';
          }
          return '[name][extname]';
        },
      },
    },
  },
  server: {
    host: '0.0.0.0', // 指定 IP，0.0.0.0 表示可从局域网访问
    port: 5173,      // 指定端口
  },
})
